##
# Copyright (c) 2006 Patrick J. Leyden III
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
##

DATA_FILE = "donut_duty.data"
PICKLE_LEVEL = 0
DEFAULT_PORT = 15701


class Duty:
    name = "NoDuty"
    short_desc = ""
    long_desc = ""
    def __init__(self, name, short_desc, long_desc, time):
        """Class constructor.

        name [string]
        short_desc [string]
        long_desc [string]
        time [long]
        """
        self.name = name
        self.short_desc = short_desc
        self.long_desc = long_desc
        self.time = time


class Member:
    def __init__(self, name, email):
        """Class constructor.

        name [string]   The name of the group member.
        email [string]  The member's email address.
        """
        self.name = name
        self.email = email
        self.groups = []
        self.duties = {}

    def add_group(self, group):
        if group not in self.groups:
            self.groups.append(group)
            group.add_member(self)

    def assign_duty(self, duty):
        self.duties[duty.name] = duty


class Group:
    def __init__(self, name):
        """Class constructor.

        name [string]   The name of the group.
        """
        self.name = name
        self.members = []
        self.duties = []

    def add_member(self, member):
        if member not in self.members:
            self.members.append(member)
            member.add_group(self)

    def add_duty(self, duty):
        def NameItr(list_):
             for item in list_:
                 yield item.name
        if duty.name not in NameItr(self.duties):
            self.duties.append(duty)


if __name__ == "__main__":
    import cPickle as pickle
    print "Running..."
    my_group = Group("Donut Club")
    my_group.add_member(Member("bill", "bill@gmail.com"))
    my_group.add_member(Member("mary", "mary@gmail.com"))
    my_group.add_member(Member("chuck", "chuck@gmail.com"))

    save_file = file(DATA_FILE, "wb")
    pickle.dump(my_group, save_file, PICKLE_LEVEL)
